package org.monster.context.core.parameter;

import org.monster.context.core.headerfilter.HeaderFilterChain;
import org.monster.context.core.request.HttpRequest;

import javax.servlet.FilterChain;

/**
 * 参数Post
 * @author Monster
 */
public class ParameterPost extends Parameter {

    /**
     * 获取 头参数
     *
     * @param request  请求
     * @param response 响应
     * @param chain    通道
     */
    @Override
    public void getHeadParameter(HttpRequest request, HttpResponse response,
                                 HeaderFilterChain chain) {
        String headerInfo = request.getHeaderInfo();
        int index = headerInfo.lastIndexOf("\r\n\r\n");
        if (index != -1) {
            String params = headerInfo.substring(index + 4,
                    headerInfo.length());
            String[] paramArray = params.split("&");
            getParams(request, paramArray);
        }
    }

    /**
     * 获取 头参数
     *
     * @param request  请求
     * @param response 响应
     * @param chain    通道
     */
    @Override
    public void getHeadParameter(HttpRequest request, HttpResponse response,
                                 FilterChain chain) {
        String headerInfo = request.getHeaderInfo();
        int index = headerInfo.lastIndexOf("\r\n\r\n");
        if (index != -1) {
            String params = headerInfo.substring(index + 4,
                    headerInfo.length());
            String[] paramArray = params.split("&");
            getParams(request, paramArray);
        }
    }
}
